// pages/problems/problems.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    itemOrder: 0,
    result:[], 
    resultIndex:{},
    resultRnd:0,
    lights: {
      a: { opacity: 1, bottom: 0, opacitySpeed: 0.015, speed: 3, limit: 500 },
      b: { opacity: 1, bottom: 0, opacitySpeed: 0.02, speed: 4, limit: 800 },
      c: { opacity: 1, bottom: 0, opacitySpeed: 0.03, speed: 5, limit: 600 }
    },
    resultList:[
      {
        name:"大闸蟹300斤",
        values:[
          "微信好友数量，还需多努力啊",
          "成熟的财富观让你脚踏实地的积累实力。",
          "理性的财富观和价值观让财神对你青睐有加。"
        ]
      }, {
        name: "现金 ¥40000",
        values: [
          "我以为生活质量的标准就是奢侈，总是一不小心就成了“月光族”。",
          "记账对你来说会是个很好的习惯。",
          "银行存款忽上忽下，爱玩升降游戏。"
        ]
      }, {
        name: "现金 ¥50000",
        values: [
          "你发现放弃是减少利益的时候，你会义无反顾地放弃，并且不会回头再看一眼。",
          "你是一个理智的人，懂得遵守市场规律，不会做出什么错误的判断。",
          "无不犹豫把自己的发财之路与朋友们分享。"
        ]
      }, {
        name: "现金 ¥60000",
        values: [
          "忍耐是你财富积累的最好方式。",
          "你的收入已经超过全国95%的人。",
          "天天好行口，天天收好票。"
        ]
      }, {
        name: "300g大金链子一条",
        values: [
          "脖子上的金链子……有点压人。",
          "老夫掐指一算，你上深度票据网，准发财！",
          "最近……有票出没，紧盯细防"
        ]
      }, {
        name: "8个iPhone XS",
        values: [
          "做业务再也不嫌手机不够用了。",
          "老夫掐指一算，票友就属你顺。",
          "史上第一个将iPhone武装到脚趾头的票友。"
        ]
      }, {
        name: "一块百达翡丽手表",
        values: [
          "票友界，就属你最嘚瑟。",
          "收票收的手疼，卖票卖的眼累，赚钱赚的心乏。",
          "最近有笔大业务要来，做好准备。"
        ]
      }, {
        name: "一辆宝马5系",
        values: [
          "票友千千万，都是你朋友。",
          "注定是一方票据大咖。",
          "五湖四海皆票友，天南地北是兄弟。"
        ]
      }, {
        name: "百元钞票一麻袋",
        values: [
          "嗨，票友，挣这么多，该考虑一下如何逃税漏税了。",
          "如果打算扎口的话，能装300万，如果不扎口，能放400万。",
          "天下票友几十万，到哪都有好兄弟。"
        ]
      }
      
    ],
    problems: [
      {
        problem: "您从事票据行业几年了?",
        options: [{ value: "A", name: "1年以下" }, { value: "B", name: "1-3年" }, { value: "C", name: "3-5年" }, { value: "D", name: "5年以上" }]
      }, {
        problem: "您的微信好友有多少个？",
        options: [{ value: "A", name: "1千人以下" }, { value: "B", name: "1千-3千" }, { value: "C", name: "3千-5千" }, { value: "D", name: "满人" }]
      }, {
        problem: "稳定的人脉关系",
        options: [{ value: "A", name: "5人以下" }, { value: "B", name: "5-10人" }, { value: "C", name: "10-50人" }, { value: "D", name: "50人以上" }]
      }, {
        problem: "喜不喜欢吃五仁月饼?",
        options: [{ value: "A", name: "我能吃到天荒地老" }, { value: "B", name: "请五仁离开月饼界" }, { value: "C", name: "佛性随缘" }]
      }
    ],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var thisObj = this;
    setInterval(function () {
      var data = thisObj.data;
      thisObj.setData({
        lights: thisObj.dealLight(data),
      })
    }, 100)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '深度票据网 中秋送祝福',

      desc: '深度票据网 中秋送祝福',

      path: '/pages/index/index'
    }
  },
  shareAppMessage:function(){
    this.onShareAppMessage();
  },
  radioChange:function(e){
    var thisObj = this;
    var result = this.data.result;
    var resultIndex=0;
    result.push(e.detail.value);
    if (result.length==3){
      resultIndex=this.countResult();
    }
    setTimeout(function(){
      var itemOrder = thisObj.data.itemOrder + 1;
      if (result.length <= 3) {
        thisObj.setData({
          itemOrder: itemOrder,
          result: result,
          resultIndex: resultIndex,
          resultRnd: Math.ceil(Math.random() * 3) - 1
        })
      }else{
        thisObj.setData({
          itemOrder: itemOrder,
          result: result,
        })
      }
      
    }, 800);
    
  },
  reset:function(){
    this.setData({
      itemOrder: 0,
      result: [],
      resultIndex: 0,
      resultRnd: Math.ceil(Math.random() * 3) - 1
    })
  },
  countResult:function (){
    var result = this.data.result;
    var resultStr = result.sort().join("");
    console.info(resultStr)
    if (resultStr.indexOf("AAA")>=0){return 0;}
    if (resultStr.indexOf("BBB") >= 0) {return 3;}
    if (resultStr.indexOf("CCC") >= 0) {return 5;}
    if (resultStr.indexOf("DDD") >= 0) {return 8;}
    if (resultStr.indexOf("AA") >= 0) {return 1;}
    if (resultStr.indexOf("BB") >= 0) {return 2;}
    if (resultStr.indexOf("CC") >= 0) {return 6;}
    if (resultStr.indexOf("DD") >= 0) {return 7;}
    return 4;
  },
  dealLight: function (data) {
    var lights = data.lights;
    this.runLight(lights.a);
    this.runLight(lights.b);
    this.runLight(lights.c);
    return lights;
  },
  runLight: function (light) {
    if (light.bottom > light.limit) {
      light.bottom = 0;
      light.opacity = 1;
    }
    if (light.bottom > light.limit - 180) {
      light.opacity = light.opacity - light.opacitySpeed;
    }
    light.bottom = light.bottom + light.speed;
  }
})